//
//  MKTabBarViewController.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/7.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  标签栏控制器

import UIKit

class MKTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.addCustomTabBar()
        self.addAllChildControllers()
    }

    
    func addCustomTabBar() -> Void {
        let tabBar = MKTabBar()
        self.setValue(tabBar, forKeyPath: "tabBar")
        self.tabBar.shadowImage = UIImage.init()
        
        var barImage = UIImage.init(named: "tabBar_bottomBg")
        barImage = barImage?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 0, 0, 0), resizingMode: UIImageResizingMode.stretch)
        
        self.tabBar.backgroundImage = barImage
    }
    
    func addAllChildControllers() -> Void {
        let homeVc = MKHomeViewController()
        self.addOneChildController(childvc: homeVc, title: "首页", imageNameNor: "tabBar_home_unselect", imageNameSel: "tabBar_home_select")
        
        let talentPoolVc = MKTalentPoolViewController()
        self.addOneChildController(childvc: talentPoolVc, title: "人才库", imageNameNor: "tabBar_ActorJob_unselect", imageNameSel: "tabBar_ActorJob_select")
        
        let releaseStepOneVc = MKReleaseStepOneViewController()
        self.addOneChildController(childvc: releaseStepOneVc, title: "", imageNameNor: "tabBar_publish_merchant_unselect", imageNameSel: "tabBar_publish_merchant_select")
        
        let newsVc = MKNewsViewController()
        self.addOneChildController(childvc: newsVc, title: "消息", imageNameNor: "tabBar_messsage_unselect", imageNameSel: "tabBar_messsage_select")
        
        let meVc = MKMeMerchantViewController()
        self.addOneChildController(childvc: meVc, title: "我的", imageNameNor: "tabBar_me_unselect", imageNameSel: "tabBar_me_select")
    }
    func addOneChildController(childvc:MKBaseViewController,title:String,imageNameNor:String, imageNameSel:String) -> Void {
        childvc.title = title
        childvc.tabBarItem.image = UIImage.init(named: imageNameNor)?.withRenderingMode(.alwaysOriginal)
        childvc.tabBarItem.selectedImage = UIImage.init(named: imageNameSel)?.withRenderingMode(.alwaysOriginal)
        
        let mutNorDic = NSMutableDictionary.init()
        mutNorDic[NSFontAttributeName] = fonts(size: 10)
        mutNorDic[NSForegroundColorAttributeName] = UIColorFromRGB(rgbValue: 0x999999, A: 1)
        childvc.tabBarItem.setTitleTextAttributes(mutNorDic as? [String : Any], for: .normal)
        
        let mutSelDic = NSMutableDictionary.init()
        mutSelDic[NSFontAttributeName] = fonts(size: 10)
        mutSelDic[NSForegroundColorAttributeName] = UIColorFromRGB(rgbValue: 0xff0051, A: 1)
        childvc.tabBarItem.setTitleTextAttributes(mutSelDic as? [String : Any], for: .selected)
        
        let nav = MKNavigationViewController.init(rootViewController: childvc)
        nav.navigationBar.isHidden = true
        self.addChildViewController(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}


